/**
 * 详情对话框
 */
var GoodsInfoDlg = {
    data: {
        goodsNo: "",
        name: "",
        title: "",
        headpic: "",
        batchNo: "",
        description: "",
        weigh: "",
        shipFee: "",
        deptid: "",
        status: "",
        createTime: "",
        updateTime: "",
        recordStatus: ""
    },
editor:null
};

layui.use(['form', 'admin', 'ax','upload','element'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var upload = layui.upload;
    var element = layui.element;

    //让当前iframe弹层高度适应
    //admin.iframeAuto();

   /* //初始化编辑器
    var E = window.wangEditor;
    var editor = new E( '#description_text');
    // 将图片大小限制为 2M
    editor.customConfig.uploadImgMaxSize = 5 * 1024 * 1024;
    editor.customConfig.uploadImgServer =Feng.ctxPath+'/upload/wang'; //'common/batch/imgUpdate';
    editor.customConfig.uploadFileName = 'file';
    editor.customConfig.customAlert = function (info){
        // info 是需要提示的内容
        alert('上传失败，请重试：' + info);
    }
    editor.create();
    GoodsInfoDlg.editor = editor;*/
    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/goods/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    //页面渲染
    form.val('goodsForm', result.data);

    //editor.txt.html(result.data.description);

    $("#imgShowVal").attr("src",Feng.ctxPath+result.data.headpic)
    $("#imgShowVal").attr("layer-src",Feng.ctxPath+result.data.headpic)
    $("#description_text").html(result.data.description)
    form.render( )



    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/goods/editItem", function (data) {
            Feng.success("更新成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.set("description",GoodsInfoDlg.editor.txt.html());
        ajax.set("headpic",  $("#headpic").val());
        ajax.start();
    });

    layer.photos({
        photos: '#layerPhoto'
        ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
    });

});